package com.hospital.hospitalsystem.modules.user.controller;

import com.hospital.hospitalsystem.base.BaseResponse;
import com.hospital.hospitalsystem.base.PageData;
import com.hospital.hospitalsystem.config.TokenVerify;
import com.hospital.hospitalsystem.modules.user.biz.UserBiz;
import com.hospital.hospitalsystem.modules.user.dto.*;
import com.hospital.hospitalsystem.utils.LoginUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author qiancheng@cqxyy.net
 * @date 2023/2/23
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
@Validated
public class UserController {

    @Autowired
    private LoginUtils loginUtils;

    @Autowired
    private UserBiz userBiz;

    @ApiOperation(value = "查看医院列表")
    @RequestMapping(path = "/hospital/list",method = RequestMethod.POST)
    public BaseResponse<PageData<HospitalListRsp>> hospitalList(@RequestBody HospitalListReq req){
        PageData<HospitalListRsp> result = userBiz.hospitalList(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "查看医生预约信息情况")
    @RequestMapping(path = "/doctor/book-case",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse doctorBookCase(@RequestBody BookCaseReq req){
        BookCaseRsp result = userBiz.doctorBookCase(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "用户预约")
    @RequestMapping(path = "/doctor/order",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse doctorOrder(@RequestBody OrderReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        userBiz.doctorOrder(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "用户删除预约")
    @RequestMapping(path = "/doctor/order-delete",method = RequestMethod.DELETE)
    @TokenVerify(type = "user")
    public BaseResponse doctorOrderDelete(@RequestBody OrderReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        userBiz.doctorOrderDelete(req);
        return BaseResponse.success();
    };

    @ApiOperation(value = "查询预约历史")
    @RequestMapping(path = "/user/order-history",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse<PageData<ListBookRsp>> userOrderHistory(@RequestBody ListBookReq req){
        req.setUserUuid(loginUtils.getUser().getUserUuid());
        PageData<ListBookRsp> result = userBiz.userOrderHistory(req);
        return BaseResponse.success(result);
    };

    @ApiOperation(value = "查询药品列表")
    @RequestMapping(path = "/user/medical-list",method = RequestMethod.POST)
    @TokenVerify(type = "user")
    public BaseResponse<PageData<MedicalRsp>> medicalList(@RequestBody MedicalListReq req){
        PageData<MedicalRsp> result = userBiz.medicalList(req);
        return BaseResponse.success(result);
    };
}
